package com.shanghai.shanghaielectric.UI.refreshView;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shanghai.shanghaielectric.Model.db.OperateInfoModel;
import com.shanghai.shanghaielectric.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * Created by wnw on 16-5-26.
 */
public class MyAdapter_operateInfo extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    //定义一个集合，接收从Activity中传递过来的数据和上下文
    private List<OperateInfoModel> mList;
    private Context mContext;

    public MyAdapter_operateInfo(Context context, List<OperateInfoModel> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(mContext).inflate(R.layout.operation_item, parent, false);
        return new MyHolder(layout);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder) {
            long id = mList.get(position).getId();

            String operateContent = mList.get(position).getOperateContent();
            long item_operateTime = mList.get(position).getOperateDate();

            ((MyHolder) holder).item_id.setText(position+1+"");
            ((MyHolder) holder).item_operateInfo.setText(operateContent);

            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日   HH:mm:ss");
            ((MyHolder) holder).item_operateTime.setText(formatter.format(new Date(item_operateTime)));

        }
    }

    class MyHolder extends RecyclerView.ViewHolder {

        TextView item_id, item_operateInfo, item_operateTime;

        public MyHolder(View itemView) {
            super(itemView);
            item_id = (TextView) itemView.findViewById(R.id.item_id);
            item_operateInfo = (TextView) itemView.findViewById(R.id.item_operateInfo);
            item_operateTime = (TextView) itemView.findViewById(R.id.item_opertime);

        }
    }

//    public void setData(ErrorInfoModel errorInfoModel){
//        mList.add(0,errorInfoModel);
//    }
}
